package com.ply.flashsalessystem.controller;


import com.ply.flashsalessystem.annotation.AuthorityName;
import com.ply.flashsalessystem.entity.pojo.OrderTime;
import com.ply.flashsalessystem.entity.result.Result;
import com.ply.flashsalessystem.mapper.OrderTimeMapper;
import com.ply.flashsalessystem.service.OrderTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.LocalTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XiaoPan
 * @since 2022-04-07
 */
@RestController
@RequestMapping("config")
@Api("时间配置 接口")
@CrossOrigin
public class OrderTimeController {

    @Autowired
    OrderTimeService orderTimeService;

    @AuthorityName(authorityId = 28, authorityName = "管理员 修改时间配置")
    @ApiOperation("管理员修改 时间配置")
    @PutMapping("admin/config/orderTime")
    @Transactional
    public Result updateOrderTime(@RequestBody OrderTime orderTime1){
        LocalTime date = orderTime1.getTime();
        OrderTime orderTime2 = orderTimeService.updateTime(date, 1);
        return Result.ok().message("修改成功 修改后的时间:" + orderTime2.getTime());
    }
    @AuthorityName(authorityId = 29, authorityName = "管理员 查询时间配置")
    @ApiOperation("管理员查询 时间配置")
    @GetMapping("admin/config/getOrderTime/")
    public Result getOrderTime(){
        OrderTime byId = orderTimeService.query(1);
        return Result.ok().message("查询成功").data("time",byId.getTime());
    }
}

